﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class GestionarConvenios_FrConsConvenios : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
            CargarEmpresas();
        if (Session["nomUsEmp"] != null || Session["nomUsr"] != null)
            if (Session["nit"] != null)
            {
                DropDownListEmpresa.SelectedValue = Session["nit"].ToString();
                DropDownListEmpresa.Enabled = false;
            }
            else
            {
                LabelMensaje.Visible = true;
                ButtonRegConvenio.Visible = true;
            }
        else
            Response.Redirect("../Error.aspx");

    }
    protected void CargarEmpresas()
    {
        Empresa tmp = new Empresa();
        List<Empresa> empresas = tmp.consultarEmpresa();
        foreach (Empresa emp in empresas)
            if (emp.ObtEstado() == 2)
                DropDownListEmpresa.Items.Add(new ListItem(emp.ObtNombre(), emp.ObtNit()));
    }

    protected void ButtonBuscar_Click(object sender, EventArgs e)
    {
        string Tipo = DropDownListTipo.SelectedValue;
        string Empresa = DropDownListEmpresa.SelectedValue;
        string Estado = DropDownListEstado.SelectedValue;

        GestionarConvenios gcb = new GestionarConvenios();
        GridViewConvenios.DataSource = gcb.BusquedaAvanzada(Estado, Tipo, Empresa);
        GridViewConvenios.DataBind();

    }

    protected void ButtonBuscarTodos_Click(object sender, EventArgs e)
    {
        GestionarConvenios gct = new GestionarConvenios();
        GridViewConvenios.DataSource = gct.BuscarTodos();
        GridViewConvenios.DataBind();

    }

    protected void ButtonRegConvenio_Click(object sender, EventArgs e)
    {
        if (DropDownListEmpresa.SelectedValue != "ninguno")
            Response.Redirect("FrRegConvenio.aspx?idEmpresa_nit=" + DropDownListEmpresa.SelectedValue);
        else
            ScriptManager.RegisterStartupScript(this, this.GetType(), "myscript", "$.modaldialog.error('No ha seleccionado una empresa!', {timeout: 4 , showClose: false });", true);
    }
    protected void GridViewConvenios_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridViewConvenios.PageIndex = e.NewPageIndex;
        GridViewConvenios.DataBind();
    }
}
